package org.hot100_6.leetcode98;

import org.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution {
        public boolean isValidBST(TreeNode root) {
            List<Integer> list = new ArrayList<>();

            tree2Array(root,list);

            Integer temp = list.get(0);

            for (int i = 1; i < list.size(); i++) {
                if (temp>=list.get(i)){
                    return false;
                }

                temp = list.get(i);
            }

            return true;
        }

        public void tree2Array(TreeNode root, List<Integer> list){


            if (root==null){
                return ;
            }


           tree2Array(root.left,list);

           list.add(root.val);

           tree2Array(root.right,list);
        }
}
